package charpter01_basic.lession02_stop_thread;

import org.junit.Test;

/**
 * while(!Thread.currentThread().isInterrupted() && more work to do) {
 *     do more work;
 * }
 */
public class StopThread implements Runnable{

    public void run() {
        int count = 0;
        while (!Thread.currentThread().isInterrupted() && count < 1000) {
            System.out.println("count = " + count++);
        }
    }

    @Test
    public void test1() throws InterruptedException {
        Thread thread = new Thread(new StopThread());
        thread.start();
        Thread.sleep(5);
        thread.interrupt();
    }
}
